﻿var pagecount = "0";
var num = 0;
var page = 1;
var keyword = ""; //关键词
var hannelid = ""; //频道id
var authid = "1"; //作者id
var hid = "";
var itemCount = 0;
$(document).ready(function () {

    if ("wap" == getUrlArgStr("sources")) {
        $(".wamtop").css("display", "none");
    }
    load(page);
    $(window).bind("scroll", function () {
        //当滚动条滚动时
        var scollTop = $(this).scrollTop() + $(this).height();
        var scollH = $(document).height();

        if (scollH - scollTop < 100) {
            // Alert("100");
            if (wait.isShow) { return; } //如果正在加载，则返回  
            page++;
            load(page);

        }
        return false;
    });
});

function load(page) {
    if (pagecount == "1") { return; }
    if (!islogin()) { window.location.href = 'login.html'; return; }
    ajax.Getconlltionlist("page_index=" + page, function (data) {
        if (data.code == "4") { Alert(data.msg.toString()); pagecount = "1"; return; }
        if (data.item.pageCount < page) {
            if (pagecount == "0")
                Alert('到底了！');
            pagecount = "1"; return;
        }
        itemCount = data.item.itemCount;
        $(".topcententxt").html("我的收藏 (" + data.item.itemCount + ")");
        $(data.item.table).each(function () {
            num++;
            var url = "";

            if (this.type == 1) {
                url = "to_detail.aspx?article_id=" + this.article_id
            }
            else if (this.type = 2) {
                url = "detail.html?is_app=1&type=2&url=" + encodeURI(this.url);
            }
            else {
                ;
            }
            var logoimg = this.article_logo == null ? "img/30.png" : this.article_logo;
            var titles = this.article_title;
            if (titles == null) {
                titles = "网页链接";
            }
            if (titles.length > 12)
                titles = titles.substr(0, 12) + "...";

            $(".tg_select").append("<div class=\"centenlist\"><div class=\" centenimg\"><img src=\"" + logoimg + "\"  /></div><div class=\"cententxt\" onclick=\"window.location.href='" + url + "'\"><div class=\"cententxttop\"><strong>" + titles + "</strong></div><div class=\"centenTime\"> " + this.date.substring(0, 10) + "<div class=\"centenflow\"><img src=\"img/flow.jpg\" />  " + (this.article_click == null ? "0" : this.article_click) + "</div><div class=\"check\"><img src=\"img/Delete2.jpg\" class=\"checkimg\"  /><input type=\"hidden\" name=\"checkid\" value=\"" + this.id + "\" /></div></div></div></div>");
        });
        loadhtml();

    });
}

function loadhtml() {
    $(".check").click(function () {
        if (confirm($(this).parent().parent().parent().find('strong').html() + "\n\n  确定删除？")) {

            DeleteCollection($(this).children(":last").val(), $(this));
        }
        return false
    });

}

function DeleteCollection(id, obj) {

    ajax.Removecollection("id=" + id, function (data) {

        if (data.msg.toString() == "成功") {
            obj.parent().parent().parent().hide(500);
            $(".topcententxt").html("我的收藏 (" + --itemCount + ")");
        }
        else {
            Alert(data.msg.toString());
        }
        return false;
    });

}



 